package com.zebra.common.concurrent;

/**
 * get configs through system properties prior to default value
 * 在默认值之前通过系统属性获取配置
 *
 * @version $Id: ConfigManager.java, v 0.1 2017-08-03 19:21 tsui Exp $
 */
public class ExecutorConfigManager {
    // ~~~ properties for bootstrap 引导程序的属性


    // ~~~ properties for processor manager 处理器管理器的属性
    public static int default_tp_min_size() {
        return getInt(ExecutorConfigs.TP_MIN_SIZE, ExecutorConfigs.TP_MIN_SIZE_DEFAULT);
    }

    public static int default_tsp_min_size(){
        return getInt(ExecutorConfigs.TSP_MIN_SIZE, ExecutorConfigs.TSP_MIN_SIZE_DEFAULT);
    }

    public static int default_tp_max_size() {
        return getInt(ExecutorConfigs.TP_MAX_SIZE, ExecutorConfigs.TP_MAX_SIZE_DEFAULT);
    }

    public static int default_tp_queue_size() {
        return getInt(ExecutorConfigs.TP_QUEUE_SIZE, ExecutorConfigs.TP_QUEUE_SIZE_DEFAULT);
    }

    public static int default_tp_keepalive_time() {
        return getInt(ExecutorConfigs.TP_KEEPALIVE_TIME, ExecutorConfigs.TP_KEEPALIVE_TIME_DEFAULT);
    }


    // ~~~ public helper methods to retrieve system property 用于检索系统属性的公共帮助方法
    public static boolean getBool(String key, String defaultValue) {
        return Boolean.parseBoolean(System.getProperty(key, defaultValue));
    }

    public static int getInt(String key, String defaultValue) {
        return Integer.parseInt(System.getProperty(key, defaultValue));
    }

    public static byte getByte(String key, String defaultValue) {
        return Byte.parseByte(System.getProperty(key, defaultValue));
    }

    public static long getLong(String key, String defaultValue) {
        return Long.parseLong(System.getProperty(key, defaultValue));
    }
}